package com.lagou.edu.controller;

import com.lagou.edu.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

/**
 * Ajax Json交互
 */
@Controller
@RequestMapping("demo")
public class JsonController {

    /**
     * 添加@ResponseBody之后，不再走视图解析器那个流程，而是等同于response直接输出数据
     */
    @RequestMapping(value = "/json")
    @ResponseBody
    public  User handleJson(@RequestBody User user) {
        Date date = new Date();
        System.out.println("date " + date  + " user ==>> " + user);
        // 业务逻辑处理，修改name为张三丰
        user.setName("张三丰");
        return user;
    }
}
